﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewModels="clr-namespace:PCController.ViewModels"
        xmlns:converters="clr-namespace:PCController.Converters"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        x:Class="PCController.MainWindow"
        Title="WP Remote Controller"
        WindowStyle="None"
        ResizeMode="CanMinimize"
        Width="500"
        Height="640"
        Icon="App.ico"
        StateChanged="Window_StateChanged"
        MouseLeftButtonDown="Window_MouseLeftButtonDown"
        Loaded="Window_Loaded"
        Closed="Window_Closed"
        Background="#FF1BA1E2"
        Foreground="White">
    <Window.Resources>
        <converters:BooleanAndMultiConverter x:Key="AndConverter" />
        <ControlTemplate x:Key="ButtonControlTemplate"
                         TargetType="{x:Type Button}">
            <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                               Storyboard.TargetName="HighlightBorder">
                                    <EasingDoubleKeyFrame KeyTime="0"
                                                          Value="1" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                               Storyboard.TargetName="HighlightBorder">
                                    <EasingDoubleKeyFrame KeyTime="0"
                                                          Value="1" />
                                </DoubleAnimationUsingKeyFrames>
                                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
                                                              Storyboard.TargetName="HighlightBorder">
                                    <EasingColorKeyFrame KeyTime="0"
                                                         Value="#FFFFB4B4" />
                                </ColorAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled" />
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border x:Name="HighlightBorder"
                        Margin="0"
                        d:LayoutOverrides="Width, Height"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        BorderBrush="{TemplateBinding Foreground}"
                        BorderThickness="1"
                        Padding="0"
                        Opacity="0"
                        Background="#00FFB4B4" />
                <TextBlock x:Name="textBlock"
                           TextWrapping="Wrap"
                           Text="{TemplateBinding Content}"
                           Foreground="{TemplateBinding Foreground}"
                           HorizontalAlignment="Right"
                           Margin="{TemplateBinding Padding}"
                           d:LayoutOverrides="Height"
                           Background="{x:Null}" />
            </Grid>
        </ControlTemplate>
        <Style x:Key="TextBlockCaptionStyle"
               TargetType="{x:Type TextBlock}">
            <Setter Property="TextWrapping"
                    Value="NoWrap" />
            <Setter Property="TextTrimming"
                    Value="None" />
            <Setter Property="FontFamily"
                    Value="Segoe UI Light" />
            <Setter Property="FontSize"
                    Value="48" />
            <Setter Property="Margin"
                    Value="0,0,0,-8" />
            <Setter Property="HorizontalAlignment"
                    Value="Right" />
        </Style>
    </Window.Resources>
    <Window.DataContext>
        <viewModels:MainWindowViewModel />
    </Window.DataContext>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBlock Text="{Binding ApplicationVersion}"
                   Grid.Row="1"
                   VerticalAlignment="Bottom"
                   HorizontalAlignment="Left"
                   FontSize="10"
                   Margin="5 0 0 3" />

        <StackPanel Orientation="Horizontal">
            <Image Height="62"
                   Margin="0"
                   Source="Content/Images/Tile_62.png"
                   Stretch="None"
                   VerticalAlignment="Top"
                   HorizontalAlignment="Left"
                   IsHitTestVisible="False" />
            <TextBlock HorizontalAlignment="Left"
                       TextWrapping="Wrap"
                       Text="Windows Phone PC Controller"
                       VerticalAlignment="Bottom"
                       Margin="0,0,0,3"
                       FontFamily="Segoe WP Light"
                       FontSize="26.667"
                       IsHitTestVisible="False" />
        </StackPanel>
        <StackPanel HorizontalAlignment="Right"
                    Margin="0,3,3,0"
                    Grid.Column="1"
                    Orientation="Horizontal"
                    VerticalAlignment="Top">
            <Button Content="_"
                    Template="{DynamicResource ButtonControlTemplate}"
                    Click="MinimizeButton_Click"
                    Margin="0,2,2,0"
                    Foreground="White"
                    Padding="3,-5,3,3"
                    ToolTip="Minimize to System Tray" />
            <Button Content="x"
                    Template="{DynamicResource ButtonControlTemplate}"
                    Click="CloseButton_Click"
                    Margin="0,2,2,0"
                    Foreground="White"
                    Padding="3,-3,3,1"
                    VerticalAlignment="Top"
                    ToolTip="Shutdown and Close" />
        </StackPanel>
        <Grid Margin="0,15,0,20"
              Grid.Row="1"
              Grid.ColumnSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock TextWrapping="Wrap"
                       Text="info"
                       FontFamily="Segoe UI Light"
                       FontSize="48"
                       Style="{DynamicResource TextBlockCaptionStyle}" />
            <StackPanel Margin="20,0"
                        VerticalAlignment="Bottom"
                        d:LayoutOverrides="Width"
                        Grid.Column="1">
                <StackPanel Margin="0,0,0,2"
                            Orientation="Horizontal">
                    <TextBlock TextWrapping="Wrap"
                               Text="Status:" />
                    <TextBlock TextWrapping="Wrap"
                               Text="{Binding Status}"
                               Margin="5,0" />
                </StackPanel>
                <StackPanel Orientation="Horizontal"
                            Margin="0">
                    <TextBlock Text="Local IP address: "
                               Margin="0 3 0 0" />
                    <ComboBox ItemsSource="{Binding AvailableIPAddresses}"
                              SelectedItem="{Binding IPAddress}"
                              Margin="5 0 5 0"
                              MinWidth="150"
                              HorizontalAlignment="Stretch"></ComboBox>
                </StackPanel>
            </StackPanel>
            <TextBlock TextWrapping="Wrap"
                       Text="options"
                       Style="{DynamicResource TextBlockCaptionStyle}"
                       Margin="0"
                       d:LayoutOverrides="HorizontalAlignment"
                       Grid.Row="1" />
            <StackPanel Margin="19,26,20,0"
                        d:LayoutOverrides="Width"
                        Grid.Row="1"
                        Grid.Column="1">
                <CheckBox Content="Use accelerometer"
                          IsChecked="{Binding Configuration.UseAccelerometer, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Style="{DynamicResource CheckBoxStyle}"
                          Foreground="White" />
                <CheckBox Content="Use touch input"
                          x:Name="UseTouchCheckBox"
                          IsChecked="{Binding Configuration.UseTouchInput, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Use relative positioning"
                          IsChecked="{Binding Configuration.TouchInputIsRelative, Mode=TwoWay}"
                          HorizontalAlignment="Left"
                          Margin="18,0,0,0"
                          Foreground="White">
                    <CheckBox.IsEnabled>
                        <MultiBinding Converter="{StaticResource AndConverter}">
                            <Binding Path="IsPhoneDeviceReady" />
                            <Binding Path="IsChecked"
                                     ElementName="UseTouchCheckBox" />
                        </MultiBinding>
                    </CheckBox.IsEnabled>
                </CheckBox>
                <CheckBox Content="Use tap gestures"
                          IsChecked="{Binding Configuration.UseTapGestures, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Use double-tap gestures"
                          IsChecked="{Binding Configuration.UseDoubleTapGestures, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Use hold gestures"
                          IsChecked="{Binding Configuration.UseHoldGestures, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Use flick gestures"
                          IsChecked="{Binding Configuration.UseFlickGestures, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          Foreground="White" />
                <CheckBox Content="Use drag gestures"
                          IsChecked="{Binding Configuration.UseDragGestures, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Use text input"
                          IsChecked="{Binding Configuration.UseTextInput, Mode=TwoWay}"
                          IsEnabled="{Binding IsPhoneDeviceReady}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <CheckBox Content="Enable Tracing"
                          x:Name="EnableTracingCheckBox"
                          Visibility="Collapsed"
                          IsChecked="{Binding Configuration.EnableTracing, Mode=TwoWay}"
                          HorizontalAlignment="Left"
                          Foreground="White" />
                <TextBox Text="{Binding Configuration.TracingEndpointAddress, Mode=TwoWay}"
                         x:Name="TracingEndpointAddressTextBox"
                         Visibility="Collapsed"
                         Margin="18,2,0,0"
                         d:LayoutOverrides="Width" />
            </StackPanel>
            <TextBlock TextWrapping="Wrap"
                       Text="log"
                       Style="{DynamicResource TextBlockCaptionStyle}"
                       Margin="0"
                       d:LayoutOverrides="HorizontalAlignment"
                       Grid.Row="2" />
            <ListBox ItemsSource="{Binding Errors}"
                     Background="White"
                     BorderBrush="#FFE2E2E2"
                     Margin="20,27,20,0"
                     Grid.Row="2"
                     Grid.Column="1" />
            <TextBlock HorizontalAlignment="Right"
                       TextWrapping="Wrap"
                       VerticalAlignment="Top"
                       Style="{DynamicResource TextBlockCaptionStyle}"
                       Grid.Row="3"
                       Margin="0,0,0,-11"><Run Text="help" /></TextBlock>
            <TextBlock Grid.Row="3"
                       Grid.Column="1"
                       Margin="20,0"
                       VerticalAlignment="Bottom"
                       Background="White"
                       HorizontalAlignment="Left"
                       Padding="10,5">
                <Hyperlink NavigateUri="http://www.pitorque.de/paarc"
                           RequestNavigate="Hyperlink_RequestNavigate"><Run Text="http://www.pitorque.de/paarc" /></Hyperlink>
            </TextBlock>
        </Grid>
    </Grid>
</Window>
